home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / gwedit.com / GSTART.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-03-16  |  3.9 KB  |  160 lines

  1.  
  2. { graphics initialization unit }
  3. { released to public domain 3/15/89 by author Michael Day }
  4.  
  5. unit Gstart;
  6.  
  7. interface
  8.  
  9. uses graph;
  10.  
  11. type rect = record Xmin,Ymin,Xmax,Ymax:integer; end;
  12.  
  13. const NoDisp   = 0;
  14.       CgaDisp  = 1;
  15.       HercDisp = 2;
  16.       EgaDisp  = 3;
  17.  
  18. const
  19.     DispType : integer = 0;
  20.     GrMode   : integer = 0;
  21.     GrDriver : integer = 0;
  22.     ErrCode  : integer = 0;
  23.     BoxTextHeight : integer = 8;
  24.     BoxTextWidth : integer = 8;
  25.     GraphOn : boolean = false;
  26.     ForceCGA : integer = 0; {override for testing}
  27.  
  28.  
  29. {---------------------------------------}
  30. {initializes the graphics display}
  31. {returns true if all went well. Returns false if not}
  32. {DispType is set to the display type we are working with}
  33. {or to NoDisp if could not install the display}
  34.  
  35. function GrafStart:boolean;
  36.  
  37. {---------------------------------------}
  38. {turn off graphics mode}
  39.  
  40. procedure SetGraphOff;
  41.  
  42. {-----------------------------------------------------------------}
  43. { Ack! Something very serious happened that we can't recover from }
  44.  
  45. procedure BombOut(Err:integer);
  46.  
  47. {---------------------------------------}
  48.  
  49. implementation
  50.  
  51. function GrafStart:boolean;
  52. begin
  53.   GrafStart := false;
  54.   GraphOn := false;
  55.   DispType := NoDisp;
  56.  
  57.   DetectGraph(GrDriver,GrMode);
  58.   Errcode := GraphResult;
  59.   if Errcode = GrOk then
  60.   begin
  61.  
  62.    if ForceCGA <> 0 then GrDriver := ForceCGA;  {override for testing}
  63.  
  64.     case GrDriver of
  65.       CGA : begin
  66.               DispType := CgaDisp;  {we like CGA (not really, but...)}
  67.               GrMode := CGAhi;
  68.               BoxTextHeight := 8;
  69.               BoxTextWidth := 8;
  70.             end;
  71.       HercMono : begin
  72.               DispType := HercDisp;  {and we like Hercules (sort of)}
  73.               GrMode := HercMonohi;
  74.               BoxTextHeight := 12;
  75.               BoxTextWidth := 8;
  76.             end;
  77.       EGA : begin
  78.               DispType := EgaDisp;  {and we like EGA}
  79.               GrMode := EGAhi;
  80.               BoxTextHeight := 12;
  81.               BoxTextWidth := 8;
  82.             end;
  83.       EGA64 : begin
  84.               DispType := CgaDisp;  {we make ega64 into cga}
  85.               GrMode := EGA64lo;
  86.               BoxTextHeight := 8;
  87.               BoxTextWidth := 8;
  88.             end;
  89.       VGA : begin
  90.               DispType := EgaDisp;  {we make VGA into EGA}
  91.               GrMode := VGAmed;
  92.               BoxTextHeight := 12;
  93.               BoxTextWidth := 8;
  94.             end;
  95.       MCGA : begin
  96.               DispType := CgaDisp;  {we make MCGA into CGA}
  97.               GrMode := MCGAmed;
  98.               BoxTextHeight := 8;
  99.               BoxTextWidth := 8;
  100.             end;
  101.       ATT400 : begin
  102.               DispType := CgaDisp;  {we make ATT400 into CGA}
  103.               GrMode := ATT400med;
  104.               BoxTextHeight := 8;
  105.               BoxTextWidth := 8;
  106.             end;
  107.     else
  108.       CloseGraph; {not a recognized display, so shut it down}
  109.     end;
  110.   end;
  111.  
  112.   if DispType = NoDisp then
  113.     GrafStart := false
  114.   else
  115.  
  116.   begin
  117.     InitGraph(GrDriver,GrMode,'');
  118.     Errcode := GraphResult;
  119.     if Errcode = GrOk then
  120.     begin
  121.       GrafStart := true;
  122.       GraphOn := true;
  123.     end
  124.     else
  125.     begin
  126.       writeln('Graphics error:',grapherrormsg(errcode));
  127.       GrafStart := false;
  128.       GraphOn := false;
  129.     end;
  130.   end;
  131. end;
  132.  
  133. {-------------------}
  134. procedure SetGraphOff;
  135. begin
  136.   Closegraph;
  137.   GraphOn := false;
  138. end;
  139.  
  140. {-------------------}
  141. procedure BombOut(Err:integer);
  142.  
  143. function ErrMsg(Err:byte):string;
  144. var S:string[8];
  145. begin
  146.    str(Err,S);
  147.    ErrMsg := S;
  148. end;
  149.  
  150. begin
  151.   SetGraphOff;
  152.   Writeln('    System error: '+ErrMsg(Err));
  153.   Writeln(' - Unable to continue, program aborted -');
  154.   Halt(Err);
  155. end;
  156.  
  157. {-------------------}
  158. {no unit init needed}
  159. end.
  160.